<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单支付</title>
    <script src="/js/jquery.js"></script>
    <iframe id="wxpay" style="display: none"></iframe>
</head>
<body>
订单编号：<input id="outtradeno" type="text" value="201809201150248563" />
<input id="btn" type="button" value="立即支付" />
<script>

    var outtradeno="";

    $(document).ready(function () {

        $("#btn").click(function () {
            outtradeno=$("#outtradeno").val();
            setTimeout('getOrderState()',5000);//轮询执行，500ms一次
            var url = "/API/Weixin/downOrder?out_trade_no="+outtradeno;
            //$("#wxpay").attr("src",url);
            window.location=url;
        });
    });

    function getOrderState() {
        var url = "/API/Weixin/getQj?key="+outtradeno;
        //alert(url);
        $.ajax({
            url: url,
            type: "GET",
            dataType: "json", //指定服务器返回的数据类型
            success: function(result) {
                if(result.msgCode=="000000")
                {
                    alert("支付成功!!");
                }
                else if(result.msgCode=="111111")
                {
                    alert("支付超时!!");
                }
                else
                {
                    setTimeout('getOrderState()',2000);//轮询执行，500ms一次
                }
            }
        });
    }

</script>
</body>
</html>